function wf = trainSimplePerceptron(X, wi, b, tol, epoch)
%TRAINSIMPLEPERCEPTRON
%   This function trains a simple perceptron with a given set
%   of patterns (X), an initial weiths (wi), the expected 
%   solution for each pattern (b). An exitation function (g)
%   and its derived function (dg) and returns the trained weiths
%   of the neuron (wf)
%   
%   Input
%
%   X:  The set of patterns.
%   wi: The initial weight for each input. 
%   b:  The expected solution for each pattern.
%   g:  activation function.
%   dg: derivated activation function.
%   epoch: number of epochs
%
%   Output:
%   wf: The vector of of the trained weigths.

    wf = wi;
    errores = [];
    epocas = [];
    for t = 1:epoch,
        wf = trainEpochSimplePerceptron(X, wf, b);
        err = errorFunction(X, wf, b);
        X = shufflePatterns(X, b);
        b = X(:,length(X(1,:)));
        X = X(:,1:length(X(1,:))-1);
        if(err < tol)
            break;
        end
        if mod(t,100) == 0
           errores = [errores, err];
           epocas = [epocas, t];
        end
        
        
    end
    plot(epocas, errores, '-');        

    disp('Error alcanzado: ');
    disp(err);
    disp('Error tolerancia: ');
    disp(tol);
    disp('Epocas: ');
    disp(t);
    
    %wf = wi;
    %Xaux = X;
    %baux = b;
    
    %for t = 1:epoch,
    %    X = shufflePatterns(Xaux, baux);
    %    X = getPpatterns(X);
    %    b = X(:,length(X(1,:)));
    %    X = X(:,1:length(X(1,:))-1);
    %    wf = trainEpochSimplePerceptron(X, wf, b);
    %    err = errorFunction(X, wf, b);
    %    if(err < tol)
    %        break;
    %    end
    %end
end